#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QApplication>
#include <QMainWindow>
#include <QDebug>
#include <QPoint>
#include <QPainter>
#include <QRect>
#include <QPushButton>
#include <QThread>
#include <QMouseEvent>
#include <QTextBrowser>
#include <QString>
#include <QTime>

#include "acoTest/acoTest.h"
#include "antColonyOptimization/antColonyOptimization.h"
#include <unistd.h>


namespace Ui {
class MainWindow;
}

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    explicit MainWindow(std::vector<std::vector<int>> m1, std::vector<std::vector<int>> m2, QWidget *parent = nullptr);
    ~MainWindow();

    std::vector<std::vector<int>> matrix1;
    std::vector<std::vector<int>> matrix2;
    std::vector<std::vector<int>> matrix;
    bool flag = false;
    bool sFlag = false;
    bool eFlag = false;


    void mouseReleaseEvent(QMouseEvent *event);


private:
    void Sleep(int msec) {
        QTime dieTime = QTime::currentTime().addMSecs(msec);
        while( QTime::currentTime() < dieTime )
        QCoreApplication::processEvents(QEventLoop::AllEvents, 100);
    }

    Ui::MainWindow *ui;

    void paintEvent(QPaintEvent *event);

    acoTest aco;
    antColonyOptimization orAco;

    std::vector<QPoint> route;
    std::vector<QPoint> oRoute;

    QPushButton* b0;
    QPushButton* b1;
    QPushButton* b2;
    QPushButton* b3;
    QPushButton* b4;
    QTextBrowser* t1;

    int scale = 0;
    int i = 0;
    int k = 0;
    double min = INT32_MAX;
    double oMin = INT32_MAX;
    int count = 0;

    std::vector<float> v1;
    std::vector<float> v1t;

    QPoint start;
    QPoint end;

    clock_t staT,endsT;

    void acoT();

    void clear() {
        i = 0;
        k = 0;
        eFlag = false;
        sFlag = false;
        flag = false;
        min = INT32_MAX;
        oMin = INT32_MAX;
        t1->clear();
        update();
    }

    void acoP();

    void sol() {
        t1->append(QString::fromStdString("优化蚁群算法："+std::to_string(min)));
    }

    void oSol() {
        t1->append(QString::fromStdString("原始蚁群算法："+std::to_string(oMin)));
    }

    void setMat1();

    void setMat2();


signals:
    void sig();

    void oSig();

};

#endif // MAINWINDOW_H
